package com.qf.mq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class MqUtils {

    /**
     * 获取连接的静态方法
     * @return
     */
    public static Connection getConnection() throws IOException, TimeoutException {

        final ConnectionFactory connectionFactory = new ConnectionFactory();

        connectionFactory.setHost("192.168.57.190");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/test");
        connectionFactory.setUsername("test");
        connectionFactory.setPassword("test");

        final Connection connection = connectionFactory.newConnection();

        return connection;

    }

    public static void main(String[] args) throws IOException, TimeoutException {
        final Connection connection = MqUtils.getConnection();
        System.out.println(connection);
        connection.close();
    }

}
